package com.cqyc.shop.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cqyc.shop.domain.Orders;
import com.cqyc.shop.domain.User;
import com.cqyc.shop.services.OrdersServices;

@WebServlet(urlPatterns="/orderslist.do")
public class OrdersListServlet extends HttpServlet{
	private static final long serialVersionUID = 5733798519556788368L;
	private Logger logger = LoggerFactory.getLogger(getClass());
	private OrdersServices ordersServices = new OrdersServices();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		logger.debug("订单显示开始表演");
		try {
			//1:从前台获取参数
			HttpSession session = request.getSession();
			Object ouser = session.getAttribute("user");
			User user = (User)ouser;
			logger.debug("{}",user.getUsercode());
			List<Orders> orders2 = ordersServices.findPager(user.getUsercode());
			request.setAttribute("orders2",orders2);
			
			/*response.sendRedirect(request.getContextPath()+"/userAccount/userOrder.jsp");*/
			request.getRequestDispatcher("/userAccount/userOrder.jsp").forward(request, response);
		} catch (Exception e) {
				logger.error("{}",e.getMessage());
				request.setAttribute("error2", e.getMessage());
				request.getRequestDispatcher("/userAccount/userOrder.jsp").forward(request, response);
		}
	
	}
	
}
